Ext.onReady(function(){
 var param = '';
/* function pollingFunction(myBaseParams)
    {
        Ext.Ajax.request(
        {
           extraParams: myBaseParams,
           url: 'polling',
           success: function(response, params)
           {
              console.log("response.responseText = " + response.responseText);
              var data = Ext.decode(response.responseText);
              console.log("data = " + data.data.future);
              
             if(data.data.future == 'a05324f5-9e88-4b79-afb3-0033ad91a939') { 
                console.log('data.data.future == a05324f5-9e88-4b79-afb3-0033ad91a939');
                param = '{future:\"' + data.data.future + '\"}';
                console.log('param = ' + param);
             }
           }
        });
 }; */
 function getParam() {
    return param;
 };
 
 Ext.define('pollingDemo', {
    entends: 'Ext.direct.PollingProvider',
    id: 'testpolling',
    type:'polling',
    url: 'polling',
    //url: pollingFunction,
    interval: 60000,
    //baseParams: param, // {start:0, limit:25, sort:"delivered", dir:"DESC", query:""},
    baseParams:{'future' : this.getParam},
    //baseParams: {start:0, limit:25, sort:"delivered", dir:"DESC", query:""},
    listeners: { 
	    data: function(provider, event, eOpts) {
	        if(!event.status) {
	            console.log('status1 = ' + event.status);   
                provider.disconnect();
	        } else {
                console.log('status2 = ' + event.status);
                //console.log('eOpts = ' + eOpts.future);
                //var data = Ext.decode(event.data);
                console.log("data = " + event.data.future);
                console.log("data = " + event.name);
                if(event.data.future == 'a05324f5-9e88-4b79-afb3-0033ad91a939') { 
                    console.log('event.data.future == a05324f5-9e88-4b79-afb3-0033ad91a939');
                    //param = '{future:\"' + event.data.future + '\"}';
                    param = event.data.future;
                    //setParam(param);
                    console.log('param = ' + param);
                    provider.disconnect();
                    
                    alert('before = ' + pollA.baseParams);
                    //provider.setBaseParams(param);
                  
                    provider.baseParams = param;
                    alert('after = ' + provider.baseParams);
                    //pollA.setUrl('polling?future=a05324f5-9e88-4b79-afb3-0033ad91a939');
                    provider.connect();
               }
            }
	    } 
   } 
 });
 

 
var pollA = Ext.create('pollingDemo');
if(param == '') {
    Ext.direct.Manager.addProvider(pollA);
    console.log('param = empty');
 
}; 

Ext.Direct.on('message', function() { console.log('message received'); });  

});